#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int sum = 0, minSum = 0, ans = INT_MIN;
        for (auto& e : nums)
        {
            sum += e;
            ans = max(ans, sum - minSum);
            minSum = min(minSum, sum);
        }
        return ans;
    }
};